﻿using Shop.Collect;
using Shop.ExtendService;
using Shop.Model.DB;
using Shop.RemoteModel.Activity.Model;
using Shop.Service.Interface;
using WeDonekRpc.Client;

namespace Shop.Service.Extend
{
    internal class ActivityDetailedSerivce : IActivityDetailedSerivce
    {
        private readonly IActivityCollect _Activity;
        private readonly IUserGradeCollect _Grade;
        private readonly IEmpService _Emp;
        private readonly IActivityGoodsService _Goods;

        public ActivityDetailedSerivce (IActivityCollect activity,
            IUserGradeCollect grade,
            IEmpService emp,
            IActivityGoodsService goods)
        {
            this._Activity = activity;
            this._Grade = grade;
            this._Emp = emp;
            this._Goods = goods;
        }

        public ActivityDetailed Get (long activityId)
        {
            DBShopActivity activity = this._Activity.Get(activityId);
            ActivityDetailed data = activity.ConvertMap<DBShopActivity, ActivityDetailed>();
            if (activity.AuditEmpId.HasValue)
            {
                data.AuditEmpName = this._Emp.GetEmpName(activity.AuditEmpId.Value);
            }
            if (data.UserGrade.HasValue)
            {
                data.GradeName = this._Grade.GetName(activity.UserGrade.Value);
            }
            data.Goods = this._Goods.Gets(activityId);
            return data;
        }
    }
}
